const router = require("koa-router")();
const JWT = require("jsonwebtoken");
const { ChatCompletion, setEnvVariable } = require("@baiducloud/qianfan");
setEnvVariable("QIANFAN_ACCESS_KEY", "ALTAKdCvPAVLDCEk6eQTRMamR1");
setEnvVariable("QIANFAN_SECRET_KEY", "ca61ec6b67cf4af4ab69491238759f3c");

//官网 https://console.bce.baidu.com/

const client = new ChatCompletion();

router.get("/aibox", async (ctx, next) => {
  // user = "user";固定的    content = "用户输入的内容"
  const { user, content } = ctx.request.query;
  const resp = await client.chat(
    {
      messages: [
        {
          role: user,
          content: content,
        },
      ],
    },
    "ERNIE-3.5-8K"
  );
  ctx.body = {
    code: 200,
    data: resp,
    message: "success",
  };
});

  
 
module.exports = router;
